<%@page import="java.math.BigDecimal"%>
<%@page import="com.opensymphony.xwork2.ActionContext"%>
<%@page import="com.milk_shop.model.Food" %>
<%@page import="java.util.List"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<% 
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<%List<Food> foods=(List<Food>)ActionContext.getContext().get("foods");%>
<base href="<%=basePath %>"/>
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>用户点单界面</title>
  <script src="js/vue.js"></script>
  <script src="js/vue-router.js"></script>
  <script src="js/httpVueLoader.js"></script>
  <link rel="stylesheet" href="https://unpkg.com/element-ui@2.14.1/lib/theme-chalk/index.css">
  <script src="https://unpkg.com/element-ui@2.14.1/lib/index.js"></script>
  <style>
    .button {
      padding: 0;
      float: right;
    }

    .product-info {
      float: left;
      text-align: left;
      margin: 20px;
    }

    .image {
      width: 150px;
      height: 150px;
      display: block;
    }

    .container {
      width: 100%;
      margin: 0 50px 0 0;
    }

    .food-card {
      text-align: center;
      width: 380px;
    }

    .food-img {
      float: left;
    }
  </style>
</head>
<div id="app">
    <el-container style="height: 650px;">
      <sider-component></sider-component>
      <div class="container">
        <el-container>
          <el-main>
            <el-row v-for="(i,row) in Math.ceil(this.items.length / 3)" :key="i" style="margin-bottom: 15px">
              <el-col :span="6" v-for="(o, col) in (i==Math.ceil(items.length / 3)?<%=foods.size() % 3==0?3:foods.size()%3 %>:3)" :key="o" :offset="col > 0 ? 3 : 0">
                <el-card class="food-card" shadow="hover">
                  <div class="food-img" @click="cardClick(items[row*3+col].id)">
                    <img :src="items[row*3+col].cover" class="image"/>
                  </div>
                  <div class="product-info">
                    <p>名称：{{items[row*3+col].name}}</p>
                    <p>原价：{{items[row*3+col].price}}</p>
                    <p>折扣优惠：{{items[row*3+col].discouont}}</p>
                    <p>现价：{{items[row*3+col].realPrice}}元</p>
                  </div>
                  <div>
                    <el-button type="danger" icon="el-icon-plus" circle @click="addFood(items[row*3+col].id)"></el-button>
                  </div>
                </el-card>
              </el-col>
            </el-row>
          </el-main>
        </el-container>
      </div>
    </el-container>
  </div>
  <script>
    Vue.use(httpVueLoader);

    new Vue({
      el: "#app",
      components: {
        'sider-component': 'url:component/SiderBar.vue',
      },
      data: {
        items: [
        <%for(Food food : foods){%>
          {
        	id:'<%=food.getId()%>',  
        	cover:'<%=food.getCover()%>',
            name: '<%=food.getName()%>',
            price: '<%=food.getPrice()%>',
            discouont:'<%=food.getDisCountString()%>',
            realPrice:'<%=food.getRealPrice()%>'
          },
          <%}%>
        ]
      },
      created() {
        console.log(this.items)
      },
      methods: {
    	addFood(id) {
    		window.location.href="order/addFood?foodId="+id;
          	alert("加入购物车成功");
        },
        cardClick(id){
        	window.location.href="order/getDetail?foodId="+id;
        }
      },
    })
  </script>
</body>

</html>